# 石头剪刀布游戏
# 导入模块
import tkinter as tk
import random

#定义函数
def rock_paper_scissors():

    #定义列表
    options = ['石头', '剪刀', '布']
    #随机选择一个选项
    computer_choice = random.choice(options)
    #提示玩家选择
    player_choice = player_choice_var.get()
    #判断游戏结果
    if player_choice == computer_choice:
        result_label.config(text="平局！")
    elif (player_choice == '石头' and computer_choice == '剪刀') or (player_choice == '剪刀' and computer_choice == '布') or (player_choice == '布' and computer_choice == '石头'):
        result_label.config(text="你赢了！")
    else:
        result_label.config(text="你输了！")

#创建窗口
root = tk.Tk()
root.title("石头剪刀布游戏")

#设置窗口大小
root.geometry("500x500")

#设置窗口背景色
root.config(bg="red")

#创建标签(布局与中间对齐)
player_label = tk.Label(root, text="请选择石头、剪刀、布中的一种：", font=("Arial", 20), bg="red", fg="white", width=30, height=2)
player_label.pack(pady=20)

#创建选择框
player_choice_var = tk.StringVar()
player_choice_var.set("石头")
player_choice_menu = tk.OptionMenu(root, player_choice_var, "石头", "剪刀", "布")
player_choice_menu.pack(pady=20)


#创建按钮
submit_button = tk.Button(root, text="开始游戏", command=rock_paper_scissors, font=("Arial", 15), bg="green", fg="white", width=10, height=2)
submit_button.pack(pady=20)


#创建结果标签
result_label = tk.Label(root, text="", font=("Arial", 20), bg="red", fg="white", width=30, height=2)
result_label.pack(pady=20)
#输出电脑随机选择结果
# result_label.config(text=computer_choice)

#启动窗口
root.mainloop()